package com.sinoglobal.ningxia.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.TextView;

import com.sinoglobal.ningxia.R;
import com.sinoglobal.ningxia.beans.AmusementInfoVo;
import com.sinoglobal.ningxia.http.ConnectionUtil;

import net.tsz.afinal.FinalBitmap;

import java.util.ArrayList;

/**
 * @Title: AmusementInfoAdapter.java
 * @Package com.sinoglobal.ningxia.adapter
 * @Description: TODO(用一句话描述该文件做什么)
 * @author czz
 * @date 2014-6-20 下午5:02:54
 */
public class AmusementInfoAdapter extends BaseAdapter implements ListAdapter{

	private Context context;
	private ArrayList<AmusementInfoVo> list = new ArrayList<AmusementInfoVo>();
	private FinalBitmap fb;
	private int type;
	
	public ArrayList<AmusementInfoVo> getList() {
		return list;
	}
	public void setList(ArrayList<AmusementInfoVo> list) {
		this.list = list;
	}
	public void setMoreList(ArrayList<AmusementInfoVo> list) {
		if(list!=null){
			this.list.addAll(list);
		}
	}
	public AmusementInfoAdapter(Context context,int type) {
		this.context = context;
		fb = FinalBitmap.create(context);
		fb.configLoadfailImage(R.drawable.default43);
		fb.configLoadingImage(R.drawable.default43);
		this.type = type;
	}
	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public AmusementInfoVo getItem(int arg0) {
		return list.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}
	@Override
	public View getView(int arg0, View arg1, ViewGroup arg2) {
		ViewHolder viewHolder = null;
		AmusementInfoVo amusementInfoVo = list.get(arg0);
		if (viewHolder == null) {
			viewHolder = new ViewHolder();
			arg1 = LayoutInflater.from(context).inflate(R.layout.layout_amusementinfo_item, null);
			viewHolder.amusementItemIv = (ImageView) arg1.findViewById(R.id.amusement_item_iv);
			viewHolder.amusementItemTv = (TextView) arg1.findViewById(R.id.amusement_item_tv);
			viewHolder.amusementItemDistance = (TextView) arg1.findViewById(R.id.amusement_item_distance);
			viewHolder.amusementItemPhone = (TextView) arg1.findViewById(R.id.amusement_item_phone);
			arg1.setTag(viewHolder);
		}
		viewHolder = (ViewHolder) arg1.getTag();
		
		if(type == 1){
			viewHolder.amusementItemTv.setText(amusementInfoVo.getShop_name());
			fb.display(viewHolder.amusementItemIv, ConnectionUtil.localUrl+amusementInfoVo.getShop_img());
			viewHolder.amusementItemDistance.setText(amusementInfoVo.getShop_juli());
			viewHolder.amusementItemPhone.setText(amusementInfoVo.getShop_tel());
		}
		else{
			viewHolder.amusementItemTv.setText(amusementInfoVo.getHouse_name());
			fb.display(viewHolder.amusementItemIv, ConnectionUtil.localUrl+amusementInfoVo.getHouse_img());
			viewHolder.amusementItemDistance.setCompoundDrawables(null, null, null, null);
			viewHolder.amusementItemPhone.setCompoundDrawables(null, null, null, null);
			viewHolder.amusementItemDistance.setText(amusementInfoVo.getHouse_address());
			viewHolder.amusementItemPhone.setText(amusementInfoVo.getHouse_price()+"元/平米");
		} 
		return arg1;
	}
	class ViewHolder{
		ImageView amusementItemIv; //图片
		TextView amusementItemTv; // 标题
		TextView amusementItemDistance; //距离
		TextView amusementItemPhone; //图片
	}

}
